﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Novacode;
using System.IO;
using System.Diagnostics;
using MusicRipperDataAccess;


namespace JewelCaseWriter
{
    public class JewelCaseHelper
    {
       
        public JewelCaseHelper()
        {
        }

        public static void WriteTheCase(Album inAlbum)
        {
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "temp.docx");
            if (File.Exists(fileName)) File.Delete(fileName);
            using (Novacode.DocX document = DocX.Create(fileName))
            {

                Paragraph p = document.InsertParagraph();
                p.Alignment = Alignment.center;
                p.AppendLine(inAlbum.Title);
                p.AppendLine(inAlbum.Artist);
                Table t = p.InsertTableAfterSelf(inAlbum.MyTracks.Count, 2);
                t.AutoFit = AutoFit.Contents;
                for (int i = 0; i < inAlbum.MyTracks.Count(); i++)
                {
                    t.Rows[i].Cells[0].Paragraphs[0].InsertText(inAlbum.MyTracks[i].OrgTitle, false);
                    t.Rows[i].Cells[1].Paragraphs[0].InsertText(inAlbum.MyTracks[i].NewTitle, false);
                }


                document.Save();
                ProcessStartInfo info = new ProcessStartInfo(fileName);
                info.Verb = "Print";
                info.CreateNoWindow = true;
                info.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(info);

            }
        }
    }
}
